/*******************************************************************************
 * Copyright (c) 2009 Kevin Bierhoff and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Kevin Bierhoff - initial API and implementation
 *******************************************************************************/
package com.googlecode.twelfdevtools.twelfast;

public class Ascription implements ITwelfTerm {
	
	public static Ascription ascr(ITwelfTerm t, ITwelfTerm a) {
		return new Ascription(t, a);
	}
	
	private final ITwelfTerm term;
	private final ITwelfTerm ascription;
	
	public Ascription(ITwelfTerm term, ITwelfTerm ascription) {
		super();
		this.term = term;
		this.ascription = ascription;
	}

	public ITwelfTerm getTerm() {
		return term;
	}

	public ITwelfTerm getAscription() {
		return ascription;
	}

	public <T> T dispatch(ITwelfAstVisitor<T> visitor) {
		return visitor.ascr(this);
	}

	@Override
	public String toString() {
		return term + " : " + ascription;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((ascription == null) ? 0 : ascription.hashCode());
		result = prime * result + ((term == null) ? 0 : term.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Ascription other = (Ascription) obj;
		if (ascription == null) {
			if (other.ascription != null)
				return false;
		} else if (!ascription.equals(other.ascription))
			return false;
		if (term == null) {
			if (other.term != null)
				return false;
		} else if (!term.equals(other.term))
			return false;
		return true;
	}

}
